package com.sikaryofficial.information.config;

import cn.hutool.core.text.CharSequenceUtil;
import com.sikaryofficial.information.domain.vo.BrandTenantVO;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author qinjinyuan
 * 功能：配置信息
 * 时间：2023/11/30 20:20
 */

@Setter
@Getter
@ToString
@RefreshScope
@Configuration
@ConfigurationProperties(prefix = "hismk.information")
public class HISMKInformationProperties {

    /**
     * 默认的语言
     */
    private String newsDefaultLang;

    /**
     * 品牌与租户对应关系
     */
    private List<BrandTenantVO> brandTenantList;

    public BrandTenantVO getByBrand(String brandNo) {
        return brandTenantList.stream().filter(item -> CharSequenceUtil.equalsIgnoreCase(item.getBrandNo(), brandNo)).findFirst().orElse(new BrandTenantVO());
    }

    public Integer getTenantByBrand(String brandNo) {
        return getByBrand(brandNo).getTenantId();
    }
}
